import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("", 5010))
server_socket.listen(5)

print "TCPServer Waiting for client on port 5000"

while 1:
    try:
        client_socket, address = server_socket.accept()
        print "I got a connection from ", address
        client_socket.send('Server online')
        while 1:
            data = client_socket.recv(512)
            print 'RECEIVED: ',data
            if data == 'closed' or data == '':
                print 'Client closed'
                client_socket.send('closed')
                client_socket.close()
                break
            else:
                if data == 'site' :
                    client_socket.send('OK')
                    data = client_socket.recv(512)
                    client_socket.send('Site to '+data)
                elif data == 'link' :
                    client_socket.send('OK')
                    data = client_socket.recv(512)
                    client_socket.send('Link to '+data)

    except KeyboardInterrupt:
        server_socket.close()
        print 'Quit'
        break
